import { MessageBox } from 'element-ui'
import Select from './index.vue'

interface SelectOptions {
  disableChecked?: boolean
}

export default (option: SelectOptions) => {
  const h = VUE.$createElement
  const msg = h(Select, { key: Math.random(), props: option }, null)
  return MessageBox({
    title: '选择批量操作应用范围',
    message: msg,
    showCancelButton: true,
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    beforeClose: (action, instance, done) => {
      if (action === 'confirm') {
        instance.confirmButtonLoading = true
        instance.confirmButtonText = '执行中...'
        setTimeout(() => {
          done()
          setTimeout(() => {
            instance.confirmButtonLoading = false
          }, 300)
        }, 300)
      } else {
        done()
      }
    },
  }).then((action) => {
    let instance: any = msg.componentInstance
    return instance.form.condition
  })
}
